package com.heima.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.mapper.VendingMachineMapper;
import com.heima.pojo.dto.VmSearchDto;
import com.heima.pojo.vo.PageResponseVo;
import com.heima.pojo.vo.VmPageVo;
import com.heima.service.VmService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class VmServiceImpl implements VmService {
    @Autowired
    private VendingMachineMapper vmMapper;

    @Override
    public PageResponseVo<VmPageVo> searchPageVm(VmSearchDto vmSearchDto) {
        Page<VmPageVo> page = new Page<VmPageVo>(vmSearchDto.getPageIndex(), vmSearchDto.getPageSize());
        List<VmPageVo> vo = vmMapper.selectPageVm(page, vmSearchDto);
        PageResponseVo<VmPageVo> responseVo = new PageResponseVo<>();
        responseVo.setPageIndex(vmSearchDto.getPageIndex());
        responseVo.setPageSize(vmSearchDto.getPageSize());
        responseVo.setTotalCount(page.getTotal());
        responseVo.setTotalPage(page.getPages());
        responseVo.setCurrentPageRecords(vo);
        return responseVo;
    }
}
